<script type="text/javascript" >
    $(document).ready(
    function(){
        
        if ( $("#typ option:selected").text() == 'iné' || $("#typ option:selected").text() == 'konferencia'){
          $('#datum').show();
          $('#den').hide();    
        }
        
        
        $('#1').click(
        function(){
            $('#datum').hide();
            $('#den').show();
         }
    )
        $('#2').click(
        function(){
            $('#datum').show();
            $('#den').hide();
        }
    )
        $('#3').click(
        function(){
            $('#datum').show();
            $('#den').hide();
        }
        
            
            
    )
           
    }
        
);
</script>

<div id="mess"><?php if (isset($mess)) echo $mess; ?></div>
<div id="form">
    <table>
        <?php
        $this->form_validation->set_error_delimiters('<span class="error">', '</span>');
        echo form_open(base_url() . 'user/editevent/'.$id);

        $event_data = array('name' => 'event_meno',
                              'id' => 'event_meno',
                            'size' => '20',
                            'value' => set_value('event_meno', $val['event_meno'])
            );
        echo "<tr><td>" . form_label('Nazov eventu:', 'event_meno') . '</td><td >' . form_input($event_data) . "</td><td>" . form_error('event_meno') . '</td></tr>';
        $pole = array();

        
        echo "<tr><td>" . form_label('Typ eventu:', 'typ') . "</td>
         <td><select name='typ' id='typ'>";
        foreach ($types as $type){
            echo "<option ";  
            if ($val['typ'] == $type['id']) echo "selected='selected'";    
            echo " value='" . $type['id'] . "' id='" . $type['id'] . "'>" . $type['event_type']."</option>";}
        echo "</select></td></tr>";


        for ($i = 1; $i < 32; $i++)
            $pole_den[$i] = $i;
        $selected = isset($val['datum']) ? (int)$val['datum'] : "";
        echo "<tr id='datum'><td>" . form_label('Dátum:', 'datum') . "</td><td>" . form_dropdown('datum', $pole_den, $selected);

        for ($i = 1; $i < 13; $i++)
            $pole_mes[$i] = $i;
        $selected = isset($val['mesiac']) ? (int)$val['mesiac'] : "";
        echo form_dropdown('mesiac', $pole_mes, $selected);

        $selected = isset($val['rok']) ? (int)$val['rok'] : "";;
        $data[$selected] = isset($_POST['rok']) ? $_POST['rok'] : $selected;
        $data[$selected + 1] = $selected + 1;
        echo form_dropdown('rok', $data, $selected) . "</td></tr>";

        $selected = isset($val['den']) ? $val['den'] : "";
        $data = array(
            '1' => 'pondelok',
            '2' => 'utorok',
            '3' => 'streda',
            '4' => 'štvrtok',
            '5' => 'piatok'
        );
        echo "<tr id='den'><td>" . form_label('Deň:', 'den') . "</td><td>" . form_dropdown('den', $data, $selected) . "</td></tr>";


        foreach ($rooms as $room) {
            $pole[$room['id']] = $room['room_name'];
        }

        $selected = $val['room'];
        echo "<tr><td>" . form_label('Miestnosť:', 'room') . "</td><td>" . form_dropdown('room', $pole, $selected) . "</td></tr>";

        for ($i = 8; $i <= 20; $i++)
            $pole_odhod[$i] = $i;
        $selected = $val['od_hod'];
        echo "<tr><td>" . form_label('Od:', 'od_hod') . "</td><td>" . form_dropdown('od_hod', $pole_odhod, $selected) . ":";

        $pole_odmin['0'] = '00';
        for ($i = 1; $i < 12; $i++)
            $pole_odmin[($i * 5)] = ($i * 5);
        $selected = $val['od_min'];
        echo form_dropdown('od_min', $pole_odmin, $selected) . "</td>";

        for ($i = 8; $i <= 20; $i++)
            $pole_dohod[$i] = $i;
        $selected = $val['do_hod'];;
        echo "<td>" . form_label('do:', 'do_hod') . form_dropdown('do_hod', $pole_odhod, $selected) . ":";

        $pole_domin['0'] = '00';
        for ($i = 1; $i < 12; $i++)
            $pole_domin[($i * 5)] = ($i * 5);
        $selected = (int)$val['do_min'];;

        echo form_dropdown('do_min', $pole_domin, $selected) . '</td></tr>';

        echo "<tr id='sub_cell'><td></td><td></td><td>" . form_submit('submit', 'Edituj event', 'id="submit"') . "</td></tr>";

        echo form_close();
        ?>    
    </table>
</div>
